Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
cspell-trie-lib
Advanced tools
The cspell-trie-lib package provides utilities for working with Trie data structures, which are particularly useful for spell checking, auto-completion, and other text processing tasks. It allows for efficient storage and retrieval of words and prefixes.
Creating a Trie
This feature allows you to create a Trie and insert words into it. The `has` method checks if a word exists in the Trie.
const { Trie } = require('cspell-trie-lib');
const trie = new Trie();
trie.insert('hello');
trie.insert('world');
console.log(trie.has('hello')); // true
console.log(trie.has('world')); // true
console.log(trie.has('hell')); // false
Finding Words with a Given Prefix
This feature allows you to find all words in the Trie that start with a given prefix. The `findWithPrefix` method returns an array of words that match the prefix.
const { Trie } = require('cspell-trie-lib');
const trie = new Trie();
trie.insert('hello');
trie.insert('hell');
trie.insert('heaven');
trie.insert('heavy');
const wordsWithHe = trie.findWithPrefix('he');
console.log(wordsWithHe); // ['hello', 'hell', 'heaven', 'heavy']
Removing a Word from the Trie
This feature allows you to remove a word from the Trie. The `remove` method deletes the specified word, and the `has` method can be used to verify its removal.
const { Trie } = require('cspell-trie-lib');
const trie = new Trie();
trie.insert('hello');
trie.insert('world');
trie.remove('hello');
console.log(trie.has('hello')); // false
console.log(trie.has('world')); // true
The trie-prefix-tree package provides similar functionality for creating and managing Trie data structures. It supports insertion, deletion, and searching for words and prefixes. Compared to cspell-trie-lib, trie-prefix-tree offers a more straightforward API but may lack some advanced features.
The dawg-lookup package implements a Directed Acyclic Word Graph (DAWG), which is a more space-efficient alternative to a Trie. It supports similar operations like insertion, deletion, and prefix searching. DAWG structures are generally more memory-efficient but can be more complex to implement and manage compared to traditional Tries.
The radix-tree package provides a compact and efficient implementation of a Radix Tree, which is a space-optimized version of a Trie. It supports similar operations such as insertion, deletion, and prefix searching. Radix Trees are generally more memory-efficient and can be faster for certain operations compared to traditional Tries.
Trie library for use with cspell
This library allows easily building of a Trie from a word list.
The resulting trie can then be compressed into a DAFSA|DAWG.
npm install -S cspell-trie-lib
TrieXv1
base=10
The header has two parts.
The first line of data is always a *
Each line is a node in the Trie.
The format of each line is:
star [char index [, char index]*]
In other words, each line has an optional *
followed by 0 or more (char, index) pairs.
A missing index implies an index of 0, which is the end of word flag.
Example Line: *s1,e
-- The word can stop here, or add an s and continue at node 1, or add an e
Word List:
becomes
Output: (Offsets are added for clarity, but do not exist in output)
Offset Output
------- --------
TrieXv1
base=10
0 *
1 d,r
2 g
3 n2
4 *e1,i3,s
5 k4
6 l5
7 a6
8 t7,w7
The root of the trie is the last offset, 8. It is designed for the entire trie to be in memory, which is why the root is at the end. This allows for efficiently building the trie as the file loads line by line, because each line can only refer to previous lines.
How to walk the data to see if "talks" is in it.
FAQs
Trie Data Structure to support cspell.
The npm package cspell-trie-lib receives a total of 553,593 weekly downloads. As such, cspell-trie-lib popularity was classified as popular.
We found that cspell-trie-lib demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.